package com.gopay.webtest.controller;

import java.io.IOException;
import java.util.Map;

import javax.annotation.Resource;

import org.dom4j.DocumentException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.webtest.vo.PayInfo;
import com.gopay.webtest.xml.XmlDao;
/**
 * 直连银行
 * @author 曹永峰
 *
 */
@Controller
public class DirectBankPayController {
	@Resource(name = "xmlDao")
	private XmlDao xmlDao;

	/**
	 * pay url mapping view controller
	 * 
	 * @return
	 */
	@RequestMapping("/directBankPay")
	public ModelAndView index() {

		ModelAndView mav = new ModelAndView();

		mav.setViewName("gopay.webtest.direct_bank_pay");
		//获取配置信息
		PayInfo payinfo = getDefaultInfoFromXML();
		mav.addObject("directBankPayInfo", payinfo);
		return mav;
	}

	@SuppressWarnings("rawtypes")
	private PayInfo getDefaultInfoFromXML() {
		PayInfo payInfo = new PayInfo();
		try {
			Map map = xmlDao.readData4Map("pay", "payapply");
			

			payInfo.setMerchantID((String) map.get("merchantID"));
			payInfo.setBackgroundMerUrl((String) map.get("backgroundMerURL"));
			payInfo.setCurrencyType((String) map.get("currType"));
			payInfo.setMerURL((String) map.get("merURL"));
			payInfo.setTranDateTime((String) map.get("tranDateTime"));
			payInfo.setTranIP((String) map.get("tranIP"));
			payInfo.setVirCardNoIn((String) map.get("virCardNoIn"));
			
		} catch (DocumentException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return payInfo;
	}
}
